Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added encounter-notes cypress test #10538

Conversation

sanjayh-2022
Copy link

@sanjayh-2022 sanjayh-2022 commented Feb 10, 2025

Proposed Changes

  • Fixes Create a new cypress test for encounter notes #10388
  • Added a file cypress\e2e\patient_spec\encounter-notes.cy.ts for the cypress test
  • Added a function to file cypress\pageObject\Patients\PatientEncounter.ts to use it in my cypress test
  • Ensured all the requirements were met

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features
    • Enhanced encounter management by enabling the creation of discussion threads and the addition of messages.
    • Improved navigation within encounters for quick access to notes and settings.
    • Streamlined workflows for different user roles, ensuring a smooth note-taking experience.
    • Added new methods for managing settings and conversations within the patient encounter context.

@sanjayh-2022 sanjayh-2022 requested a review from a team as a code owner February 10, 2025 10:55
Copy link
Contributor

coderabbitai bot commented Feb 10, 2025

Walkthrough

The changes introduce a new Cypress test suite for encounter notes and enhance the PatientEncounter page object. The test suite includes scenarios for creating discussion threads and adding messages, executed from both doctor and nurse perspectives. The page object now supports navigation to settings and notes tabs, starting new conversations, and appending messages to threads. These modifications improve the automated test coverage for encounter notes functionality.

Changes

File(s) Change Summary
cypress/e2e/.../encouter-notes.cy.ts Added a Cypress test suite for encounter notes with tests for creating multiple threads and adding messages for both doctor and nurse roles.
cypress/pageObject/.../PatientEncounter.ts Expanded the PatientEncounter class with new methods: openSettingsTab(), openNotesTab(), addMessageToThread(message: string), and startNewConversation().

Possibly related PRs

Suggested labels

tested, reviewed

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

I hopped through lines of code so bright,
With tests that run both day and night,
Encounter notes now spring to life,
In threads where chats avoid all strife,
My bunny paws tap with delight,
Celebrating changes with pure insight! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Feb 10, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 80e28e1
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67b57eabbf1b850008a370ca
😎 Deploy Preview https://deploy-preview-10538.preview.ohc.network
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
cypress/e2e/patient_spec/encouter-notes.cy.ts (2)

26-26: Fix typo in test message.

The test message contains a typo: "fianl" should be "final".

-      cy.get("textarea").type("This is a test message fianl!");
+      cy.get("textarea").type("This is a test message final!");

14-77: Reduce code duplication by extracting helper functions.

The code for creating threads and adding messages is duplicated across test cases. Consider extracting this into a helper function for better maintainability.

function createThreadWithMessage(title: string, message: string) {
  cy.contains("button", "New Thread").click();
  cy.get("input[placeholder='Enter discussion title...']").type(title);
  cy.contains("button", "Create").click();
  cy.get("form").within(() => {
    cy.get("textarea").type(message);
    cy.get('button[type="submit"]').click();
  });
}

// Usage in tests:
it("create multiple threads and add messages", () => {
  patientEncounter
    .navigateToEncounters()
    .openFirstEncounterDetails()
    .openNotesTab();

  createThreadWithMessage("Test Discussion final", "This is a test message final!");
  createThreadWithMessage("Test Discussion 100", "This is a test message 100!");
});
🧰 Tools
🪛 ESLint

[error] 18-19: Replace ⏎······ with ;

(prettier/prettier)


[error] 23-23: Replace "Test·Discussion·final" with ⏎······"Test·Discussion·final",⏎····

(prettier/prettier)


[error] 30-32: Delete ⏎⏎····

(prettier/prettier)


[error] 34-34: Replace "Test·Discussion·100" with ⏎······"Test·Discussion·100",⏎····

(prettier/prettier)


[error] 41-42: Replace ··cy.intercept("POST",·"https://careapi.ohc.network/api/v1/auth/logout/").as("logoutRequest");⏎ with cy.intercept("POST",·"https://careapi.ohc.network/api/v1/auth/logout/").as(⏎······"logoutRequest",

(prettier/prettier)


[error] 43-43: Insert );

(prettier/prettier)


[error] 49-49: Replace .navigateToEncounters().openFirstEncounterDetails() with ⏎······.navigateToEncounters()⏎······.openFirstEncounterDetails()⏎······

(prettier/prettier)


[error] 56-56: Insert ;

(prettier/prettier)


[error] 60-60: Replace "Test·Discussion·200" with ⏎······"Test·Discussion·200",⏎····

(prettier/prettier)


[error] 65-67: Delete ⏎⏎····

(prettier/prettier)


[error] 71-71: Replace "Test·Discussion·300" with ⏎······"Test·Discussion·300",⏎····

(prettier/prettier)

cypress/pageObject/Patients/PatientEncounter.ts (3)

35-38: Fix formatting issues.

The method has formatting issues that should be addressed.

-openNotesTab() {
-    cy.get('#encounter_tab_nav').contains("Notes").click();
+ openNotesTab() {
+    cy.get("#encounter_tab_nav").contains("Notes").click();
🧰 Tools
🪛 ESLint

[error] 35-35: Insert ·

(prettier/prettier)


[error] 36-36: Replace '#encounter_tab_nav' with "#encounter_tab_nav"

(prettier/prettier)


40-44: Remove redundant comment.

The comment "Click the submit button" is redundant as the code is self-documenting.

  addMessageToThread(message: string) {
    cy.get('textarea[placeholder="Type your message"]').type(message);
-    // Click the submit button
    cy.get('button[type="submit"]').click();
  }

46-51: LGTM! Remove extra blank line.

The method is well-implemented but has an extra blank line that should be removed.

  startNewConversation() {
    cy.contains("button", "Start New Discussion").should("be.visible").click();
    return this;
  }
-
🧰 Tools
🪛 ESLint

[error] 49-50: Delete

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d0c3406 and 86096e7.

📒 Files selected for processing (2)
  • cypress/e2e/patient_spec/encouter-notes.cy.ts (1 hunks)
  • cypress/pageObject/Patients/PatientEncounter.ts (1 hunks)
🧰 Additional context used
🪛 ESLint
cypress/pageObject/Patients/PatientEncounter.ts

[error] 35-35: Insert ·

(prettier/prettier)


[error] 36-36: Replace '#encounter_tab_nav' with "#encounter_tab_nav"

(prettier/prettier)


[error] 49-50: Delete

(prettier/prettier)

cypress/e2e/patient_spec/encouter-notes.cy.ts

[error] 1-1: Replace FacilityCreation·}·from·"@/pageObject/facility/FacilityCreation with PatientEncounter·}·from·"@/pageObject/Patients/PatientEncounter

(prettier/prettier)


[error] 2-2: Replace PatientEncounter·}·from·"@/pageObject/Patients/PatientEncounter with FacilityCreation·}·from·"@/pageObject/facility/FacilityCreation

(prettier/prettier)


[error] 18-19: Replace ⏎······ with ;

(prettier/prettier)


[error] 23-23: Replace "Test·Discussion·final" with ⏎······"Test·Discussion·final",⏎····

(prettier/prettier)


[error] 30-32: Delete ⏎⏎····

(prettier/prettier)


[error] 34-34: Replace "Test·Discussion·100" with ⏎······"Test·Discussion·100",⏎····

(prettier/prettier)


[error] 41-42: Replace ··cy.intercept("POST",·"https://careapi.ohc.network/api/v1/auth/logout/").as("logoutRequest");⏎ with cy.intercept("POST",·"https://careapi.ohc.network/api/v1/auth/logout/").as(⏎······"logoutRequest",

(prettier/prettier)


[error] 43-43: Insert );

(prettier/prettier)


[error] 49-49: Replace .navigateToEncounters().openFirstEncounterDetails() with ⏎······.navigateToEncounters()⏎······.openFirstEncounterDetails()⏎······

(prettier/prettier)


[error] 56-56: Insert ;

(prettier/prettier)


[error] 60-60: Replace "Test·Discussion·200" with ⏎······"Test·Discussion·200",⏎····

(prettier/prettier)


[error] 65-67: Delete ⏎⏎····

(prettier/prettier)


[error] 71-71: Replace "Test·Discussion·300" with ⏎······"Test·Discussion·300",⏎····

(prettier/prettier)

🔇 Additional comments (1)
cypress/pageObject/Patients/PatientEncounter.ts (1)

30-33: LGTM!

The method follows the page object pattern and correctly implements method chaining.

cy.get('button[type="submit"]').click();
});

cy.intercept("POST", "https://careapi.ohc.network/api/v1/auth/logout/").as("logoutRequest");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Separate test cases for different user roles.

The test case mixes doctor and nurse actions, which violates the single responsibility principle for tests. Consider splitting this into two separate test cases for better maintainability and clarity.

-  cy.intercept("POST", "https://careapi.ohc.network/api/v1/auth/logout/").as("logoutRequest");
-
-    
-
-    // logging as nurse
-    cy.loginByApi("devnurse");
-    cy.visit("/");
-    facilityCreation.selectFacility("GHC Trikaripur");
-    patientEncounter.navigateToEncounters().openFirstEncounterDetails().openNotesTab();
+  });
+
+  it("create multiple threads and add messages as nurse", () => {
+    cy.loginByApi("devnurse");
+    cy.visit("/");
+    facilityCreation.selectFacility("GHC Trikaripur");
+    patientEncounter
+      .navigateToEncounters()
+      .openFirstEncounterDetails()
+      .openNotesTab();

Also applies to: 45-49

🧰 Tools
🪛 ESLint

[error] 41-42: Replace ··cy.intercept("POST",·"https://careapi.ohc.network/api/v1/auth/logout/").as("logoutRequest");⏎ with cy.intercept("POST",·"https://careapi.ohc.network/api/v1/auth/logout/").as(⏎······"logoutRequest",

(prettier/prettier)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
cypress/pageObject/Patients/PatientEncounter.ts (1)

46-50: Use data-cy attribute for more reliable selector.

The method uses text content for selection which could break if the button text changes. Consider using a data-cy attribute instead.

Apply this diff to improve the method and fix formatting:

  startNewConversation() {
-    cy.contains("button", "Start New Discussion").should("be.visible").click();
+    cy.get('[data-cy="start-discussion"]')
+      .should("be.visible")
+      .click();
     return this;
   }
-
🧰 Tools
🪛 ESLint

[error] 49-50: Delete

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86096e7 and a4e432b.

📒 Files selected for processing (1)
  • cypress/pageObject/Patients/PatientEncounter.ts (1 hunks)
🧰 Additional context used
🪛 ESLint
cypress/pageObject/Patients/PatientEncounter.ts

[error] 35-35: Insert ·

(prettier/prettier)


[error] 36-36: Replace '#encounter_tab_nav' with "#encounter_tab_nav"

(prettier/prettier)


[error] 49-50: Delete

(prettier/prettier)

🔇 Additional comments (1)
cypress/pageObject/Patients/PatientEncounter.ts (1)

30-33: LGTM!

The method follows the page object pattern and maintains consistency with existing selectors.

Comment on lines +40 to +44
addMessageToThread(message: string) {
cy.get('textarea[placeholder="Type your message"]').type(message);
// Click the submit button
cy.get('button[type="submit"]').click();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve test maintainability and method chaining.

The method has several areas for improvement:

  1. Use data-cy attributes for more reliable selectors
  2. Return this to support method chaining

Apply this diff to improve the method:

  addMessageToThread(message: string) {
-    cy.get('textarea[placeholder="Type your message"]').type(message);
-    // Click the submit button
-    cy.get('button[type="submit"]').click();
+    cy.get('[data-cy="message-input"]').type(message);
+    cy.get('[data-cy="submit-message"]').click();
+    return this;
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
addMessageToThread(message: string) {
cy.get('textarea[placeholder="Type your message"]').type(message);
// Click the submit button
cy.get('button[type="submit"]').click();
}
addMessageToThread(message: string) {
cy.get('[data-cy="message-input"]').type(message);
cy.get('[data-cy="submit-message"]').click();
return this;
}

Comment on lines +35 to +38
openNotesTab() {
cy.get('#encounter_tab_nav').contains("Notes").click();
return this;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fix formatting issues.

The method logic is correct, but there are some formatting issues to address.

Apply this diff to fix the formatting:

- openNotesTab() {
-    cy.get('#encounter_tab_nav').contains("Notes").click();
+ openNotesTab() {
+    cy.get("#encounter_tab_nav").contains("Notes").click();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
openNotesTab() {
cy.get('#encounter_tab_nav').contains("Notes").click();
return this;
}
openNotesTab() {
cy.get("#encounter_tab_nav").contains("Notes").click();
return this;
}
🧰 Tools
🪛 ESLint

[error] 35-35: Insert ·

(prettier/prettier)


[error] 36-36: Replace '#encounter_tab_nav' with "#encounter_tab_nav"

(prettier/prettier)

@Jacobjeevan
Copy link
Contributor

@nihal467 is on vacation this week, he will review and test once he's back 👍

Copy link
Member

@nihal467 nihal467 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Make sure you follow the guidelines already mentioned in the issue as well as the POM structure
  • the entire test need to be rewritten following the guideline
  • Before writing a test, think of the workflow you are about to write test for example: A user creates a thread, then posts a note. The user logs out and logs in as a different user, then navigates to the same patient accessed by the first user. The new user verifies that they can see the message posted by the first user and adds a comment to the same thread.

beforeEach(() => {
cy.loginByApi("devdoctor"); // logging in as doctor
cy.visit("/");
facilityCreation.selectFacility("GHC Trikaripur");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
facilityCreation.selectFacility("GHC Trikaripur");
facilityCreation.selectFacility("GHC Payyanur");

use the facility GHC Payyanur


describe("Encounter Notes - Threads, Messages, and Notes", () => {
beforeEach(() => {
cy.loginByApi("devdoctor"); // logging in as doctor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.loginByApi("devdoctor"); // logging in as doctor
cy.loginByApi("devdoctor"); // logging in as doctor
  • since we are connected to develop backend temporarily, create a new user manually in the develop, add it to the fixture file and use that in your test



// first Thread
cy.contains("button", "New Thread").click();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.contains("button", "New Thread").click();
cy.contains("button", "New Thread").click();

as the per given guidelines, use the command function, cy.verifyandclickelement() to click on any button with text. Make sure you uses a proper data-cy test id's or element id ,

cy.get("input[placeholder='Enter discussion title...']").type("Test Discussion final");
cy.contains("button", "Create").click();
cy.get("form").within(() => {
cy.get("textarea").type("This is a test message fianl!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.get("textarea").type("This is a test message fianl!");
cy.get("textarea").type("This is a test message fianl!");

use combination of single line message as well as multi line text as well

@nihal467 nihal467 removed their assignment Feb 18, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
cypress/pageObject/Patients/PatientEncounter.ts (1)

45-48: Use data-cy attribute for more reliable selector.

The text-based selector could be fragile if the button text changes. Consider using a data-cy attribute for better test maintainability.

Apply this diff to improve the selector:

-    cy.contains("button", "Start New Discussion").should("be.visible").click();
+    cy.get('[data-cy="start-discussion-button"]').should("be.visible").click();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4e432b and 80e28e1.

📒 Files selected for processing (1)
  • cypress/pageObject/Patients/PatientEncounter.ts (1 hunks)
🧰 Additional context used
🪛 ESLint
cypress/pageObject/Patients/PatientEncounter.ts

[error] 34-34: Insert ·

(prettier/prettier)


[error] 35-35: Replace '#encounter_tab_nav' with "#encounter_tab_nav"

(prettier/prettier)


[error] 48-49: Delete

(prettier/prettier)

🔇 Additional comments (3)
cypress/pageObject/Patients/PatientEncounter.ts (3)

29-32: LGTM!

The method follows the established patterns in the class, using consistent selectors and proper method chaining.


34-37: Fix formatting issues.

The method logic is correct, but there are some formatting issues to address.

🧰 Tools
🪛 ESLint

[error] 34-34: Insert ·

(prettier/prettier)


[error] 35-35: Replace '#encounter_tab_nav' with "#encounter_tab_nav"

(prettier/prettier)


39-43: Improve test maintainability and method chaining.

The method has several areas for improvement:

  1. Use data-cy attributes for more reliable selectors
  2. Return this to support method chaining

@nihal467
Copy link
Member

@sanjayh-2022 what is the status of this PR

@sanjayh-2022
Copy link
Author

@sanjayh-2022 what is the status of this PR

I am working on it I will raise a pr soon

@nihal467
Copy link
Member

@sanjayh-2022 Closing this PR due to inactivity and non-compliance with the guidelines. Feel free to reopen it once the code is properly refactored and ready for review.

@nihal467 nihal467 closed this Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes required invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a new cypress test for encounter notes
3 participants